//
//  customtabViewCell.m
//  xinhua_sx
//
//  Created by love on 14-8-6.
//  Copyright (c) 2014年 dangyangyang. All rights reserved.
//

#import "customtabViewCell.h"

#import "XHTableViewCell.h"
#import "AFNetworking.h"
#import "UIImageView+AFNetworking.h"
#import "GTMNSString+HTML.h"
@implementation customtabViewCell

@synthesize lanmuLabel;
@synthesize hitL;
@synthesize destLabel;
@synthesize imageV;
@synthesize V1;
@synthesize titleLabel;

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
         self.urlString = [[XHURLString alloc]init];
        UIView* v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 25)];
        v.backgroundColor = [customtabViewCell colorWithHexString:@"#DCDCDC"];//DCDCDC
        [self addSubview:v];
        v.alpha = 0.8;
        UILabel* l1 = [[UILabel alloc] initWithFrame:CGRectMake(8, 2, 3, 21)];
        l1.backgroundColor = [UIColor redColor];
        [self addSubview:l1];
        self.lanmuLabel = [[UILabel alloc] initWithFrame:CGRectMake(18, 0, 60, 25)];
        self.lanmuLabel.backgroundColor = [UIColor clearColor];
        self.lanmuLabel.textColor = [UIColor blueColor];
        self.lanmuLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:self.lanmuLabel];
        UILabel* l2 = [[UILabel alloc] initWithFrame:CGRectMake(260, 0, 40, 25)];
        l2.backgroundColor = [UIColor clearColor];
        l2.text = @"更多>";
        l2.textColor = [UIColor redColor];
        l2.font = [UIFont systemFontOfSize:11];
        [self addSubview:l2];
        
        self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(8, 30, 60, 60)];
        self.imageV.contentMode = UIViewContentModeScaleToFill;
        self.imageV.image = [UIImage imageNamed:@"base_detail_default_pic.png"];
        [self addSubview:self.imageV];
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 30, 215, 30)];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.numberOfLines = 2;
        self.titleLabel.backgroundColor = [UIColor clearColor];
        
        [self addSubview:self.titleLabel];
        UIImageView* imagevs = [[UIImageView alloc] initWithFrame:CGRectMake(245, 80, 22, 14)];
        //imagevs.contentMode = UIViewContentModeScaleToFill;
        imagevs.backgroundColor = [UIColor clearColor];
        imagevs.image = [UIImage imageNamed:@"news_listview_item_attention.png"];
        [self addSubview:imagevs];
        
        self.hitL = [[UILabel alloc] initWithFrame:CGRectMake(260+12,82 , 28, 10)];
        self.hitL.font = [UIFont systemFontOfSize:8];
        self.hitL.textColor = [UIColor grayColor];
        self.hitL.textAlignment = NSTextAlignmentLeft;
        self.hitL.backgroundColor = [UIColor clearColor];
        self.hitL.text = @"0";
        [self addSubview:self.hitL];
        UIView* v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 95, 300, 0.3)];
        v2.backgroundColor = [UIColor grayColor];
        [self addSubview:v2];
        
        
    }
    return self;
}
+ (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}
-(void)setdic:(id)dic

{
    //NSLog(@"dic = %@",dic);
    self.titleLabel.text= [dic objectForKey:@"title"];
    self.titleLabel.text = [self.titleLabel.text gtm_stringByUnescapingFromHTML ];
    NSString* string = [dic objectForKey:@"image"];
    if([string hasPrefix:@"http"])
    {
        
        NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",string]];
        NSLog(@"url = %@",url);
        [self.imageV setImageWithURL:url placeholderImage:[UIImage imageNamed:@"base_detail_default_pic"]];
    }
    else
    {
        NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",string]];
        [self.imageV setImageWithURL:url placeholderImage:[UIImage imageNamed:@"base_detail_default_pic"]];
    }
    //NSString *imageString = [NSString stringWithFormat:@"%@%@",self.urlString.ipAndPort,[dic objectForKey:@"image"]];
    
    //[self.imageV setImageWithURL:[NSURL URLWithString:imageString] placeholderImage:[UIImage imageNamed:@"base_detail_default_pic"]];
    id hits = [dic objectForKey:@"hits"];
    if ( hits) {
        self.hitL.text = [NSString stringWithFormat:@"%@",hits];
    }
}
-(void)setLan:(NSString *)sting
{
    self.lanmuLabel.text = sting;

}
@end
